﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebNext.Domain.Entities;
using MyWeb.WebUI.Models;
using System.Web.Mvc;
using System.Collections;
using WebNext.UI.Utils;
using WebNext.UI.Properties;

namespace WebNext.UI.Models.Entries
{
	public class EntriesViewModel : MainViewModel, IEnumerable<EntryViewModel>
	{
		private List<EntryViewModel> entries;

		public EntriesPagingModel Paging
		{
			get;
			private set;
		}

		public EntriesViewModel(IEnumerable<Entry> entries, EntriesPagingModel pagingModel, bool isLogged) : base(isLogged)
		{
			this.entries = new List<EntryViewModel>(entries.Select(e => new EntryViewModel(e, isLogged)));
			this.Paging = pagingModel;

			this.ViewType = pagingModel.ViewType;

			if (this.ViewType == MainViewType.Blog)
			{
				this.PageTitle = string.Format(Resources.TitleFormat, RuntimeSettings.SitePrefix, Resources.Blog);
				this.PageName = RuntimeSettings.SitePrefix;
				this.PageDescription = Resources.MyBlog;
			}
			else
			{
				this.PageTitle = string.Format(Resources.TitleFormat, RuntimeSettings.SitePrefix, Resources.Projects);
				this.PageName = Resources.Projects;
				this.PageDescription = Resources.MyProjects;
			}
		}

		public IEnumerator<EntryViewModel> GetEnumerator()
		{
			return this.entries.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return this.entries.GetEnumerator();
		}
	}
}